---
import { getCollection } from 'astro:content';
import { processFrontmatter } from '../../integrations/process-frontmatter';
import ArchivesLayout from '../../layouts/ArchivesLayout.astro';
import { config_site } from '../../utils/config-adapter';

// 获取文章集合
export const allPosts = await getCollection('posts');
export const processedPosts = await Promise.all(allPosts.map(post => processFrontmatter(post)));

// 按日期排序
const sortedPosts = processedPosts.sort((a, b) => {
  const dateA = a.data.date ? new Date(a.data.date).getTime() : 0;
  const dateB = b.data.date ? new Date(b.data.date).getTime() : 0;
  return dateB - dateA;
});

// 页面标题和描述
const pageTitle = '文章归档 | ' + config_site.siteName;
const description = '时间轴上的所有文章';
---

<ArchivesLayout
  pageTitle={pageTitle}
  description={description}
  posts={sortedPosts}
  totalPostsCount={sortedPosts.length}
  noindex={false}
>
  <!-- 如果需要向布局组件传递额外内容，可以使用slot -->
  <!-- <div slot="head">额外的head内容</div> -->
  <!-- <div slot="main">额外的main内容</div> -->
</ArchivesLayout>